#include <stdio.h>
#include <string.h>
#include <math.h>
int er2shi(char ch1[],int n1);
int san2shi(char ch2[],int n2);

int main()
{
    int i,j,j1=0,j2=0,k=0,l1,l2;
    int num1[99999],num2[99999];
    char n21[99999],n22[99999],n31[99999],n32[99999];

    gets(n21);
    gets(n31);
    l1=strlen(n21);
    l2=strlen(n31);

    for(i=0;i<l1;i++)
    {
        strcpy(n22,n21);
        if(n22[i]=='0')
            n22[i]='1';
        else
            n22[i]='0';
        num1[j1++]=er2shi(n22,l1);
    }

    for(i=0;i<l2;i++)
    {
        k=0;
        strcpy(n32,n31);
        while (k<2)
        {
            n32[i]++;
            if(n32[i]=='3')
                n32[i]='0';
            num2[j2++]=er2shi(n32,l2);
            k++;
        }
    }

    for(i=0;i<j1;i++)
        for(j=0;j<j2;j++)
        {
            if(num1[i]==num2[j])
            {
                printf("%d\n",num1[i]);
                break;
            }
        }
    return 0;
}

int er2shi(char ch1[],int n1)
{
    int n,sum=0;
    for(n=0;n<n1;n++)
    {
        sum=sum+(ch1[n]-'0')*pow(2,n1-n-1);
    }

    return sum;
}


int san2shi(char ch2[],int n2)
{
    int n,sum=0;
    for(n=0;n<n2;n++)
    {
        sum=sum+(ch2[n]-'0')*pow(3,n2-n-1);
    }

    return sum;
}